﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RPG1
{
    public partial class FormMain : Form
    {
        Weapon wpnMagician1;
        Weapon wpnWarrior1;
        Weapon wpnNecromancer1;
        Weapon wpnMinotaur1;

        Magician magician1;
        Warrior warrior1;
        Necromancer necromancer1;
        Minotaur minotaur1;
        //List<Role> attakers;
        //List<Role> enemies;
        List<Role> heros;
        List<Role> monsters;
        public FormMain()
        {
            InitializeComponent();
        }
        private void FormMain_Load(object sender, EventArgs e)
        {
            heros = new List<Role>();
            monsters = new List<Role>();

            wpnMagician1 = new Weapon("wand", 1, 1, 10, 0, 3);
            wpnWarrior1 = new Weapon("sword", 1, 1, 20, 2, 1);
            wpnNecromancer1 = new Weapon("magicRing", 1, 1, 30, 2, 3);
            wpnMinotaur1 = new Weapon("axe", 1, 1, 30, 0, 3);
            
            magician1 = new Magician("magician1", 100, 100, 50, 0, 5, 9, picBoxHero1, labelBottomHero1, labelTopHero1, wpnMagician1, picBoxWeapon1);
            warrior1 = new Warrior("warrior 1", 100, 100, 80, 30, 3, 6, picBoxHero2, labelBottomHero2, labelTopHero2, wpnWarrior1);
            necromancer1 = new Necromancer("necromancer1", 100, 7, 100, 30, 10, 8, pictureBoxMonster1, labelBottomMonster1, labelTopMonster1, wpnNecromancer1, picBoxWeapon2);
            minotaur1 = new Minotaur("minotaur1", 100, 100, 10, 10, 4, 5, pictureBoxMonster2, labelBottomMonster2, labelTopMonster2, wpnMinotaur1);
            
            heros.Add(magician1);
            heros.Add(warrior1);
            monsters.Add(necromancer1);
            monsters.Add(minotaur1);

            heros.Sort(delegate (Role x, Role y) { return y.Speed.CompareTo(x.Speed); });
            monsters.Sort(delegate (Role x, Role y) { return y.Speed.CompareTo(x.Speed); });
            if(heros[0].Speed < monsters[0].Speed)
            {
                monsters[0].Delay(100000);
                //MessageBox.Show("" + heros[0].Speed +","+ monsters[0].Speed+"," + heros[1].Speed + "," + monsters[1].Speed);
                 foreach ( Role monster in monsters)
                {
                    monster.attack(heros[0]);
                    if (heros[0].CurrentLife <= 0) {
                        heros[0].died();
                        heros.Remove(heros[0]);
                    }
                }
                if (heros.Count == 0) {
                    MessageBox.Show("You Loss!");
                    return;
                }
            }
            //attakers = heros[0].Speed > monsters[0].Speed? heros:monsters;
            //enemies = heros[0].Speed > monsters[0].Speed ? monsters : heros;
        }

        private void picBoxAttack_Click(object sender, EventArgs e) {
            foreach (Role hero in heros)
            {
                hero.attack(monsters[0]);
                if (monsters[0].CurrentLife <= 0) {
                    monsters[0].died();
                    monsters.Remove(monsters[0]);
                    if (monsters.Count == 0)
                    {
                        MessageBox.Show("You Win!");
                        picBoxAttack.Enabled = false;
                        return;
                    }
                }
            }
           
            foreach (Role monster in monsters)
            {
                monster.attack(heros[0]);
                if (heros[0].CurrentLife <= 0)
                {
                    heros[0].died();
                    heros.Remove(monsters[0]);
                    if (heros.Count == 0)
                    {
                        MessageBox.Show("You Loss!");
                        picBoxAttack.Enabled = false;
                        return;
                    }
                }
            }
        }
    }
}
